package com.sgb.trip.view.adapter;

import android.content.Context;

import androidx.databinding.DataBindingUtil;

import com.sgb.trip.R;
import com.sgb.trip.databinding.TripItemChosenPassengerInfoBinding;
import com.sgb.trip.entity.PassengerInfoEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

/**
 * Time:2021/6/18
 * Author:黄淋
 * Description:订单页已选择的乘客信息的adapter
 */
public class PassengerInfoChosenAdapter extends BaseRecycleAdapter<PassengerInfoEntity> {


    public PassengerInfoChosenAdapter(Context context, List<PassengerInfoEntity> datas) {
        super(context, R.layout.trip_item_chosen_passenger_info, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, PassengerInfoEntity entity) {
        final int position = holder.getIndex_position();
        TripItemChosenPassengerInfoBinding binding = DataBindingUtil.bind(holder.itemView);
        binding.tvPassengerName.setText(entity.getName());
        binding.tvPassengerIdCard.setText("身份证 " + entity.getIdCard());
        binding.tvNumber.setText(position + 1 + "");
        if (onClickItem != null) {
            binding.tvPassengerEdit.setOnClickListener(view -> onClickItem.onEdit(entity));
            binding.tvPassengerDelete.setOnClickListener(view -> onClickItem.onDelete(entity));
        }

    }

    public interface OnClickItem {
        void onEdit(PassengerInfoEntity entity);//编辑

        void onDelete(PassengerInfoEntity entity);//删除
    }

    OnClickItem onClickItem;

    public void setOnClickItem(OnClickItem onClickItem) {
        this.onClickItem = onClickItem;
    }
}
